package org.spring.beans.factory.support;

import static org.junit.Assert.assertNotNull;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.spring.beans.factory.config.SingletonBeanRegistry;

public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {
	private final Map<String, Object> singteltonObjects = new ConcurrentHashMap<String, Object>();

	public void registry(String beanName, Object singletonObject) {
		assertNotNull(beanName,"beanName must not be null");
		Object singleton = this.getSingleton(beanName);
		if(singleton != null) {
			throw new IllegalStateException("Could not register object [" + singletonObject +
					"] under bean name '" + beanName + "': there is already object [" + singletonObject + "] bound");
		}
		singteltonObjects.put(beanName, singletonObject);
	}

	public Object getSingleton(String beanName) {
		return this.singteltonObjects.get(beanName);
	}


}
